package com.mt.channel.service.impl;

import java.util.List;
import java.util.Map;


import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.mt.channel.api.service.IChannelMsgService;
import com.mt.channel.entity.ChannelMsgEntity;
import com.mt.channel.service.model.ChannelMsgServiceModel;
import com.mt.common.PagerInfo;
import com.mt.common.ServiceResult;
import com.mt.common.constants.BaseErrorConstants;
import org.springframework.stereotype.Service;

@Service
public class ChannelMsgServiceImpl implements IChannelMsgService {

    private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(ChannelMsgServiceImpl.class);

    @Autowired
    private ChannelMsgServiceModel channelMsgServiceModel;

    /**
     * 查询渠道商信息
     *
     * @param params
     * @return
     */
    public ServiceResult<ChannelMsgEntity> findInfo(Map<String, Object> params) {
        ServiceResult<ChannelMsgEntity> result = null;
        try {
            result = channelMsgServiceModel.selectInfo(params);
        } catch (Exception e) {
            LOGGER.error("[ChannelMsgServiceImpl][findInfo]：query findInfo occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "查询详情错误");
        }
        return result;
    }

    /**
     * 查询渠道商信息列表
     *
     * @param params
     * @param pagerInfo
     * @return
     */
    public ServiceResult<List<ChannelMsgEntity>> findList(Map<String, Object> params, PagerInfo<?> pagerInfo) {
        ServiceResult<List<ChannelMsgEntity>> result = new ServiceResult<List<ChannelMsgEntity>>();
        try {
            result = channelMsgServiceModel.selectList(params, pagerInfo);
        } catch (Exception e) {
            LOGGER.error("[ChannelMsgServiceImpl][findList]：query findList occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "查询列表错误");
        }
        return result;
    }

    /**
     * 根据主键修改渠道商信息
     *
     * @param channelMsgEntity
     * @return
     */
    public ServiceResult<Integer> doUpdate(ChannelMsgEntity channelMsgEntity) {
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        try {
            result = channelMsgServiceModel.updateRelate(channelMsgEntity);
        } catch (Exception e) {
            LOGGER.error("[ChannelMsgServiceImpl][doUpdate]：query doUpdate occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "编辑信息错误");
        }
        return result;
    }

    /**
     * /** 增加渠道商通知
     *
     * @param channelMsgEntity
     * @return
     */
    public ServiceResult<Integer> doInsert(ChannelMsgEntity channelMsgEntity) {
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        try {
            result = channelMsgServiceModel.insert(channelMsgEntity);
        } catch (Exception e) {
            LOGGER.error("[ChannelMsgServiceImpl][doInsert]：query doInsert occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "创建信息错误");
        }
        return result;
    }

    public ServiceResult<Integer> doInsertList(List<ChannelMsgEntity> channelMsgEntityList) {
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        try {
            result = channelMsgServiceModel.insertList(channelMsgEntityList);
        } catch (Exception e) {
            LOGGER.error("[ChannelMsgServiceImpl][doInsertList]：query doInsert occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "创建信息错误");
        }
        return result;
    }

    public ServiceResult<Integer> updateList(Map<String, Object> params) {
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        try {
            result = channelMsgServiceModel.updateList(params);
        } catch (Exception e) {
            LOGGER.error("[ChannelMsgServiceImpl][updateList]：query doInsert occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "创建信息错误");
        }
        return result;
    }

    /**
     * mt-edu-admin项目需要调用
     *
     * @param channelMsgId
     * @return
     */
    public ServiceResult<Integer> doDeleteById(Integer channelMsgId) {
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        try {
            result = channelMsgServiceModel.doDeleteById(channelMsgId);
        } catch (Exception e) {
            LOGGER.error("[ChannelMsgServiceImpl][doDeleteById]：doDeleteById occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "编辑信息错误");
        }
        return result;
    }

    public ServiceResult<Integer> selectCount(Map<String, Object> params) {
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        try {
            result = channelMsgServiceModel.selectCount(params);
        } catch (Exception e) {
            LOGGER.error("[ChannelMsgServiceImpl][selectCount]：selectCount occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "查询数");
        }
        return result;
    }
}
